﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Odds.DataAccess;
using System.Text;
using Odds.Entity;
using System.Web.UI.HtmlControls;

public partial class Football_14Game_AnalysisBeginAndEndByIssue : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtIssueRealID.Text = new OddsIssueController().GetLastIssueRealNumber().ToString();
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string issueRealID = txtIssueRealID.Text;
        decimal adjust = decimal.Parse(txtAdjust.Text);
        List<OddsBeginAndEndCount> datasource =
            new OddsSPController().GetIssueOddsBeginAndEndRecordCountByIssueIDWithAdjust(issueRealID, adjust, int.Parse(ddlMatchType.SelectedItem.Value));

        string output = string.Empty;
        if(datasource.Count()>0)
        {
            output = CreateTable(datasource);
        }
        else
        {
            output = "没有您要找的记录！";
        }
        panel.InnerHtml = output.ToString();
    }

    private string CreateTable(List<OddsBeginAndEndCount> datasource)
    {
        StringBuilder result = new StringBuilder();
        byte itemID = 0;


        string[] tableTitle = { "Match", "Company", "Begin Win-Draw-Lose", "End Win-Draw-Lose", "Result Win-Draw-Lose" };


        result.Append(@"<table class=""tableHistory"" border=""1px"">");
        result.AppendFormat(@"<th>Match</th><th>Company</th><th>Begin Win-Draw-Lose</th><th>End Win-Draw-Lose</th><th>Win</th><th>Draw</th><th>Lose</th>");

        for (int i = 0; i < datasource.Count; i++)
        {
            OddsBeginAndEndCount item = datasource[i];
            if (i % 2 == 0)
            {
                result.Append(@"<tr style=""background-color:#D6D6D6"">");
            }
            else
            {
                result.Append(@"<tr style=""background-color:#FFEC8B;"">");
            }


            if (item.IndexInIssue != itemID)
            {
                result.AppendFormat(@"<td rowspan=""{0}"">序号 {1}<br />{2} - {3}</td>",
                    datasource.Where(d => d.IndexInIssue == item.IndexInIssue).Count().ToString(),
                    item.IndexInIssue, item.HomeTeam, item.VisitingTeam);
            }

            result.AppendFormat(@"<td>{0}</td><td>{1} - {2} - {3}</td><td>{4} - {5} - {6}</td><td>{7}</td><td>{8}</td><td>{9}</td>",
                    item.CompanyName, item.OddsWinBegin, item.OddsDrawBegin, item.OddsLoseBegin, item.OddsWinEnd, item.OddsDrawEnd, item.OddsLoseEnd,
                    item.WinCount, item.DrawCount, item.LoseCount);
            result.Append("</tr>");

            itemID = item.IndexInIssue;
        }
        result.Append("</table>");

        return result.ToString();
    }
}